package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.NewsXiangQing;
import com.ysd.entity.XinWen;
import com.ysd.util.DBManger;

public class NewsXiangQingDaoImpl {
	public List<NewsXiangQing> getNewsXiangQing(int newsId){
		List <NewsXiangQing> newsList = new ArrayList<NewsXiangQing>();
		
		Connection conn = DBManger.getConnection();
		Statement st=null;
		ResultSet rs = null;
		
		try {
			st= conn.createStatement();
			rs=st.executeQuery("select * from newsxiangqing where xwXiangQingId="+newsId);
			while(rs.next()) {
				int newsxqid=rs.getInt("xwXiangQingId");
				String xwbt = rs.getString("xwBiaoTi");
				String xwnr = rs.getString("xwNeiRong");
				NewsXiangQing newsXiangQing = new NewsXiangQing(newsxqid, xwbt, xwnr);
				
				newsList.add(newsXiangQing);
				
				
			}
			return newsList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManger.closeAll(conn, st, rs);
		}
	}
	
	public List<NewsXiangQing> getNewsXiangQingShang(int sId){//上一条
		List <NewsXiangQing> newsListS = new ArrayList<NewsXiangQing>();
		
		Connection conn = DBManger.getConnection();
		Statement st=null;
		ResultSet rs = null;
		
		try {
			st= conn.createStatement();
			rs=st.executeQuery("select * from newsxiangqing where xwXiangQingId = (select max(xwXiangQingId) from newsxiangqing where xwXiangQingId < "+sId+"");
			
			while(rs.next()) {
				int newsxqidS=rs.getInt("xwXiangQingId");
				String xwbtS = rs.getString("xwBiaoTi");
				String xwnrS = rs.getString("xwNeiRong");
				NewsXiangQing newsXiangQingShangS = new NewsXiangQing(newsxqidS, xwbtS, xwnrS);
				
				newsListS.add(newsXiangQingShangS);
				
				
			}
			return newsListS;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManger.closeAll(conn, st, rs);
		}
	}
	
	
	
	
	
	
}
